package Dao;

import Model.Student;
import UserView.UseUi;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DaoStuHandle {
    public void showStuDAO(Student[] stus,int len){
        for (int i = 0; i < len; i++) {
            System.out.println("stus[i] = " + stus[i]);
        }
    }
    public void addStuDAO(Student[] stus,Student stu){
        stus[UseUi.num++]=stu;
    }
    public void delStuDAO(Student[] stus,Integer len,Integer w){
        for (int i = w; i < len-1; i++) {
            stus[i]=stus[i+1];
        }
    }

    public void updateStuDAO(Student[] stus,Integer w){
        Student student = new Student();

        Scanner scanner = new Scanner(System.in);
        System.out.println("你要修改的初始姓名为"+stus[w].getName());
        System.out.println("请输入你要修改的姓名");
        String name=scanner.nextLine();
        if (name.equals("")){
            student.setName(stus[w].getName());
        }else {
            student.setName(name);
        }

        System.out.println("你要修改的初始性别为"+stus[w].getSex());
        System.out.println("请输入你要修改的性别");
        String sex=scanner.nextLine();
        if (sex.equals("")){
            student.setSex(stus[w].getSex());
        }else {
            student.setSex(sex);
        }

        System.out.println("你要修改的初始年龄为"+stus[w].getAge());
        System.out.println("请输入你要修改的年龄");
        String age=scanner.nextLine();
        if (age.equals("")){
            student.setAge(stus[w].getAge());
        }else {
            student.setAge(Integer.valueOf(age));
        }

        System.out.println("你要修改的初始专业为"+stus[w].getMajor());
        System.out.println("请输入你要修改的专业");
        String major=scanner.nextLine();
        if (major.equals("")){
            student.setMajor(stus[w].getMajor());
        }else {
            student.setMajor(major);
        }

        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format= simpleDateFormat.format(date);
        student.setTime(format);
        student.setId(stus[w].getId());
        stus[w]=student;
    }
}
